App.controller('customerLinesController', ['$rootScope', '$scope', '$state', '$window', 'Page',function($rootScope, $scope, $state, $window, Page) {
		$scope.planStatus = $state.params.planStatus;
		
		$scope.all = [];
		$scope.catalogs = [];
		
		var linesUrl = 'line/customer/' + ($scope.planStatus == '1' ? 'opened.do' : 'toBeOpen.do');
		Page.ajaxPost(linesUrl, {}, function(resp) { 
			$scope.all = resp.data;
			$scope.catalogs = resp.data;
        });
		
		$scope.search = {};
		$scope.searchLine = function(){
			$scope.searched = true;
			$scope.catalogs = [];
			if($scope.search.key != ''){
				$scope.searchKey = $scope.search.key;
				$($scope.all).each(function(idx,catalog){
					 if(catalog.catalog != '' && catalog.catalog.indexOf($scope.search.key) != -1){
						 $scope.catalogs.push(catalog);
						 return;
					 }
					 var lines = catalog.lines;
					 $(lines).each(function(idx,line){
						 if(line.lineName != '' && line.lineName.indexOf($scope.search.key) != -1){
							 $scope.catalogs.push(catalog);
							 return false;
						 }
					 });
				});
			}else{
				$scope.searchKey = '';
				$scope.catalogs = $scope.all;
			}
		};
		
}]);